package com.yuexun.dhdoctor.module.email.ui;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.email.bean.MailMainData;
import com.yuexun.dhdoctor.module.email.model.impl.MailMainModel;
import com.yuexun.dhdoctor.module.email.presenter.impl.MailMainPresenter;
import com.yuexun.dhdoctor.module.email.ui.view.IMailMainView;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2016/7/28.
 */
public class Act_MailMain extends BaseKJActivity implements IMailMainView {
    @Bind(R.id.mail_get_count)
    TextView mailGetCount;
    @Bind(R.id.mail_draft_count)
    TextView mailDraftCount;

    MailMainPresenter presenter;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_mailmain);
        ButterKnife.bind(this);

        presenter = new MailMainPresenter(new MailMainModel(), this);

    }

    public void onResume() {
        super.onResume();
        mailGetCount.setVisibility(View.GONE);
        mailDraftCount.setVisibility(View.GONE);
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        presenter.unreadData(params);
    }


    @OnClick({R.id.back, R.id.ic_mail_get_ll, R.id.ic_mail_send_ll, R.id.ic_mail_draft_ll, R.id.mail_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.ic_mail_get_ll:
                Intent intent_get = new Intent(this, Act_GetMailList.class);
                startActivity(intent_get);
                break;
            case R.id.ic_mail_send_ll:
                Intent intent_send = new Intent(this, Act_SendMailList.class);
                startActivity(intent_send);
                break;
            case R.id.ic_mail_draft_ll:
                Intent intent_draft = new Intent(this, Act_DraftMailList.class);
                startActivity(intent_draft);
                break;
            case R.id.mail_send:
                Intent intent = new Intent(this, Act_SendMail.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void ShowUnreadData(MailMainData mailMainData) {
        if ((mailMainData.getStatus().equals("200"))) {
            if (mailMainData.getDatas().get(0) > 0) {
                mailGetCount.setVisibility(View.VISIBLE);
                mailGetCount.setText(mailMainData.getDatas().get(0) + "");
            }
        }
    }

}
